package com.content.view.Component.Button
{
	import com.content.model.LoadedAssets.FontProxy;
	import com.library.core.IDisposable;
	import com.library.core.UIObject;
	import com.library.utils.TextFieldUtil;
	
	import flash.display.DisplayObject;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import flash.text.TextFormatAlign;
	
	public class TextButton2Obj extends UIObject implements IDisposable
	{
		public var id:String;
		
		protected var _colText:uint;
		protected var _colTextOver:uint;
		
		protected var _container:Sprite;
		protected var _mask:Shape;
		
		protected var _obj:DisplayObject;
		protected var _objActive:DisplayObject;		
		protected var _text:TextField;
		
		public function TextButton2Obj(txt:String, colorText:uint, colorTextOver:uint, obj:DisplayObject, objActive:DisplayObject)
		{
			super();
			this.mouseChildren = false;
			this.buttonMode = true;
			
			_colText = colorText;
			_colTextOver = colorTextOver;
			
			_container = new Sprite();
			addChild(_container);
			
			_obj = obj;
			_objActive = objActive;
			_objActive.visible = false;
			
			_text = TextFieldUtil.Generate(txt, 14, _colText, FontProxy.FONT_YAHEI);
			
			_container.addChild(_obj);
			_container.addChild(_objActive);
			_container.addChild(_text);
			
			_text.x = int((_obj.width - _text.width)/2);
			_text.y = int((_obj.height - _text.height)/2);
			
			_mask = new Shape();
			addChild(_mask);
			_mask.graphics.beginFill( 0xff0000, 1.0);
			_mask.graphics.drawRect(0,0, _obj.width, _obj.height);
			_container.mask = _mask;
			
			this.addEventListener(MouseEvent.MOUSE_OVER, OnOver);
			this.addEventListener(MouseEvent.MOUSE_OUT, OnOut);
		}
		
		/* Event Handler
		* -------------------------------------------------------------*/
		protected function OnOver(evt:MouseEvent):void{
			_text.textColor = _colTextOver;
			_obj.visible = false;
			_objActive.visible = true;
		}
		protected function OnOut(evt:MouseEvent):void{
			
			_text.textColor = _colText;
			_obj.visible = true;
			_objActive.visible = false;
		}
		
		protected function CenterPivot():void{
			_mask.x = _container.x = int(_obj.width/2)*-1;
			_mask.y = _container.y = int(_obj.height/2)*-1;
		}
		
		public function Dispose():void
		{
			this.removeEventListener(MouseEvent.MOUSE_OVER, OnOver);
			this.removeEventListener(MouseEvent.MOUSE_OUT, OnOut);
		}
	}
}